package view;

import java.awt.AWTException;
import java.awt.Robot;
import java.util.HashMap;
import java.util.Observable;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;

/**
 * This class represents a single Cell in the game's Board.<br>
 * extends {@link Observable}
 * @author Barak & Tom
 */
public class Cell extends Canvas {
	public HashMap<Integer, Image> cells;
	protected int value;

	
	public Cell(Composite parent, int style , HashMap<Integer, Image> hcells ) {
		super(parent, style);
		cells = new HashMap<>();
		value = 0;
		this.cells = hcells;
			
		addPaintListener(new PaintListener() {
			@Override
			public void paintControl(PaintEvent e) {
				int oWidth = e.width;
				int oHigth = e.height;
				e.gc.drawImage(cells.get(value), 0, 0, cells.get(value).getBounds().width, cells.get(value).getBounds().height, 0, 0, oWidth, oHigth);
				Robot r;
				try {
					r = new Robot();
					r.keyPress(SWT.TAB);r.keyPress(SWT.TAB);r.keyPress(SWT.TAB);
				} catch (AWTException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}
		
	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
		redraw();
	}
		
	public HashMap<Integer, Image> getCells() {
		return cells;
	}
	
	
	
	


}
